const express = require('express');
const router = express.Router();
const bookController = require('../controllers/bookController');

// 查询书籍信息
router.get('/information', bookController.getBooks);

// 上传封面
router.post('/uploadCover', bookController.uploadCover, (req, res) => {
    if (!req.file) {
        return res.status(400).json({ code: 1, message: '上传失败' });
    }
    res.json({
        code: 0,
        message: '上传成功',
        url: `http://localhost:3000/uploads/${req.file.filename}`
    });
});

// 添加书籍
router.post('/addBook', express.json(), bookController.addBook);

// 编辑书籍
router.post('/editBook', express.json(), bookController.editBook);

// 删除书籍
router.post('/deleteBook', express.json(), bookController.deleteBook);

module.exports = router;
